#!/bin/sh
#
# Copyright (C) 2000-2022 Kern Sibbald
# License: BSD 2-Clause; see file LICENSE-FOSS
#

#
#  Run a job with small Maximum Volume Bytes.  It should
#    create a lot of volumes. The test stresses auto-creation of
#    Volumes and restores from a lot of Volumes. Note, it creates
#    writes and then reads something like 110 Volumes (will vary
#    depending on the size of the Bacula source).
#
TestName="maxbytes-test"
JobName=maxbytes
. scripts/functions

scripts/cleanup
scripts/copy-test-confs
echo "${cwd}/build" >${cwd}/tmp/file-list

cp -f ${cwd}/bin/bacula-dir.conf ${cwd}/tmp/1
sed "s%# Maximum Volume Bytes%  Maximum Volume Bytes%" ${cwd}/tmp/1 >${cwd}/bin/bacula-dir.conf
cp -f ${cwd}/bin/bacula-dir.conf ${cwd}/tmp/1
sed "s%# Simple Label Format%  Label Format%" ${cwd}/tmp/1 >${cwd}/bin/bacula-dir.conf

change_jobname NightlySave $JobName
start_test

cat <<END_OF_DATA >${cwd}/tmp/bconcmds
@output /dev/null
messages
@$out   ${cwd}/tmp/log1.out
setdebug level=50 Storage=File1
run job=$JobName level=Full Storage=File1 yes
wait
list volumes
messages
@# 
@# now do a restore
@#
@$out   ${cwd}/tmp/log2.out
restore where=${cwd}/tmp/bacula-restores select storage=File1
unmark *
mark *
done
yes
wait
reload
@#reload
status client
cancel inactive jobid=1,2
messages
quit
END_OF_DATA

run_bacula
check_for_zombie_jobs storage=File1
stop_bacula

check_two_logs
check_restore_diff
end_test
